package com.op.teachingliteapp.sender;

import android.widget.RadioGroup;
import com.op.teachingliteapp.R;
import com.op.teachingliteapp.util.ScreenCapUtil;
import io.netty.channel.ChannelHandlerContext;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

public class Runtime {
    //    当前接受端的ip地址
    private static String ip = null;
    //    当前接收端的通道
    private static ChannelHandlerContext context;
    //    当前发送的view
    private static View view;
    //    是否发送view的标志
    private static boolean isSend = false;
    private static ImageButton sendButton;
    private static Button deviceScanBtn;
    private static RadioGroup radioGroup;

    public static String getIp() {
        return ip;
    }

    public static void setIp(String ip) {
        Runtime.ip = ip;
    }


    public static ChannelHandlerContext getContext() {
        return context;
    }

    public static void setContext(ChannelHandlerContext context) {
        Runtime.context = context;
    }

    public static View getView() {
        return view;
    }

    public static void setView(View view) {
        Runtime.view = view;
    }

    /**
     * 开始传屏
     */
    public static void play() {
        isSend = true;
        sendButton.setBackgroundResource(R.drawable.ic_pause_btn);


    }

    /**
     * 暂停传屏
     */
    public static void pause() {
        isSend = false;
        sendButton.setBackgroundResource(R.drawable.ic_play_btn);
    }


    public static void refreshStatus() {

        if (context != null) {
            radioGroup.setVisibility(View.VISIBLE);
            deviceScanBtn.setBackgroundResource(R.drawable.ic_router_on);
            checkSendStatus();


        } else {
            radioGroup.setVisibility(View.GONE);
            deviceScanBtn.setBackgroundResource(R.drawable.ic_router_off);
            checkSendStatus();

        }


    }

    private static void checkSendStatus() {
        if (isSend()) {
            sendButton.setBackgroundResource(R.drawable.ic_pause_btn);

        } else {
            sendButton.setBackgroundResource(R.drawable.ic_play_btn);
        }


    }

    public static void refreshStatus(ImageButton sendButton, Button deviceScanBtn, RadioGroup radioGroup) {
        Runtime.sendButton = sendButton;
        Runtime.deviceScanBtn = deviceScanBtn;
        Runtime.radioGroup = radioGroup;

        refreshStatus();


    }

    //是否断线
    public static boolean isOffLine() {
        return context == null;

    }

    public static boolean isSend() {
        return isSend;
    }

}
